from pydantic import BaseModel, Field
from typing import Optional
from fastapi import File, UploadFile

from .base import BaseSchema, BaseApiOut


class AccessTokenBase(BaseSchema):
    access_token: Optional[str] = Field(None, description='access token 值')
    token_type: Optional[str] = Field(None, description='token 类型: Bearer')
    expire: Optional[int] = Field(7200, description='access token有效期 (单位秒)')


class AccessToken(BaseApiOut):
    data: AccessTokenBase | None


class TokenData(BaseSchema):
    uid: Optional[int] = None
    username: Optional[str] = None


class CaptchaBase(BaseSchema):
    captcha_key: Optional[str] = ''
    captcha_image: Optional[str] = ''
    expire: int = 0


class CaptcheData(BaseApiOut):
    data: CaptchaBase


class LoginForm(BaseModel):
    username: str = Field('', description='用户名')
    password: str = Field('', description='密码')
    # captcha_key: str = ''
    captcha: str = ''


class ResetPassword(BaseModel):
    old_password: str
    password: str
    re_password: str


class FileForm(BaseModel):
    file: UploadFile = File()
    type: Optional[str] = 'config'
    origin_name: Optional[bool] = False
